<?php
require('lib/verify.php');
require('lib/has_char.php');
require('lib/is_approved.php');

$system_id = $system["system_id"];

$raid_id = $_POST["raid_id"];

$chara = $character["character_id"];;
$comments = $db->escape($_POST["comments"]);

//need to check if we're already signed up

$sql = "select * from wm_scheduled_signups where scheduled_signup_raid = $raid_id and scheduled_signup_character = $chara";
$result = $db->query($sql);

if($db->num_rows($result)>0) {
  header("Location: signup.php?id=$raid_id&error=You're+already+signed+up.");
  exit;
}

$sql = "insert into wm_scheduled_signups (scheduled_signup_character, scheduled_signup_raid, scheduled_signup_comments, scheduled_signup_system_id) values ($chara, $raid_id, '$comments', $system_id)";

$result = $db->query($sql);

$now = time();

$log_entry = "$chara signed up for $raid_id";

$sql = "insert into wm_logs (log_character, log_type, log_description, log_datetime, log_system_id) values ($chara, 'Signup', '$log_entry', FROM_UNIXTIME($now), $system_id)";
$result = $db->query($sql);


header("Location: signup.php?id=$raid_id");

?>